<template>
        <el-card shadow="never" style="max-height: 700px; overflow: auto">
            <el-form ref="form" :model="form" :rules="rules" label-width="90px" :disabled="disabled">

                <!-- <el-button type="primary" plain icon="el-icon-download" size="mini" v-loading="exportLoading" @click="handleExport">导出</el-button> -->

                <el-form-item label="id:" prop="id" v-show="false">
                    <el-input v-model="form.id" disabled />
                </el-form-item>

                <el-form-item label="总广告费($):" prop="advertising">
                    <el-input-number v-model="form.advertising" :step="0.001" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm">确认 </el-button>
                    <el-button type="warning" @click="cancel">取消 </el-button>
                </el-form-item>
            </el-form>
        </el-card>
</template>

<script>
export default {
    name: 'EditForm',
    props: {
        findFormData: {
            type: Object,
            default: {}
        },
        editFormParams: {
            type: Object,
            default: {}
        },
        // 表单是否禁用
        disabled: {
            type: Boolean,
            default: false,
        },
        
    },
    data() {
        return {
            // 编辑表单验证规则
            rules: {
        
            },
            form: {  }, 
            datalist:[], 
            queryParams:[], 
            admin_name:'未知', 
            exportLoading: false,
            // 接口地址
            api: {
                export: `/admin/personreport/export_personreport_day`,
            },
        }
    },
    watch: {
        findFormData: {
            handler(nval) {
                if (JSON.stringify(nval) != '{}') {
                    this.$nextTick(() => {
                        this.form = nval
                        this.datalist = nval.list
                        this.queryParams.admin_id = nval.admin_id
                        this.admin_name = nval.admin_name
                        this.queryParams.start_time = nval.start_time
                        this.queryParams.end_time = nval.end_time
                    })
                }
            },
            immediate: true,
            deep: false,
        },
        
    },
    methods: {
        // 取消按钮
        cancel() {
            this.$emit('editFormCancel')
        },

        submitForm() {
            this.$refs['form'].validate((valid, obj) => {
                if (valid) {
                    this.$emit('submitForm', this.form)
                }
            })
        },

        // 表单重置
        reset() {
            this.resetForm('form')
        },
        
        // 导出按钮操作
        handleExport() {
            const qyparams = {
                admin_id: this.queryParams.admin_id,
                start_time: this.queryParams.start_time,
                end_time: this.queryParams.end_time,
            }
            this.$confirm('是否确认导出当月数据?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            })
                .then(() => {
                    this.exportLoading = true
                    return this.request.get('/admin/personreport/export_personreport_day', { params: qyparams, responseType: 'blob' })
                })
                .then(response => {
                    this.download(response, this.admin_name+'当月每日业绩.xlsx')
                })
                .catch(err => {})
                .finally(() => {
                    this.exportLoading = false
                })
        },
    }
}
</script>
